﻿using UnityEngine;

/// <summary>
///     The Encapsulation of Control with Bahaviour.
/// </summary>
public class BehaviourUtil
{
    public static T AddMissingComponent<T>(GameObject obj) where T : Component
    {
        if (obj == null)
        {
            return null;
        }

        return obj.AddMissingComponent<T>();
    }

    public static T AddMissingComponent<T>(Transform trans) where T : Component
    {
        if (trans == null)
        {
            return null;
        }

        if (trans.gameObject == null)
        {
            return null;
        }

        return trans.gameObject.AddMissingComponent<T>();
    }

    public static T AddComponent<T>(GameObject obj) where T : Component
    {
        if (obj == null)
        {
            return null;
        }

        return obj.AddComponent<T>();
    }

    public static T AddComponent<T>(Transform trans) where T : Component
    {
        if (trans == null)
        {
            return null;
        }

        if (trans.gameObject == null)
        {
            return null;
        }

        return trans.gameObject.AddComponent<T>();
    }

    public static object GetComponent<T>(GameObject obj)
    {
        if (obj == null)
        {
            return null;
        }

        return obj.GetComponent<T>();
    }

    public static object GetComponent<T>(Transform trans)
    {
        if (trans == null)
        {
            return null;
        }

        if (trans.gameObject == null)
        {
            return null;
        }

        return trans.gameObject.GetComponent<T>();
    }
}